// 问题：求均方距离
const square = (v: number) => v * v;
const sqrt = Math.sqrt;

// 过程式
const msd_pp = (arr: Array<number>) => {
    let sum = 0;
    for (let i = 0; i < arr.length; i++) {
        sum += square(arr[i]);
    }
    return sqrt(sum);
}

console.log(msd_pp([1, 2, 3]));

// 函数式
import R from "ramda"

const msd_fp = R.pipe(R.map(square), R.sum, sqrt);
console.log(msd_fp([1, 2, 3]));
